package com.hmall.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
@Slf4j
public class SearchController {

    @Autowired
    SearchService searchService;

    @GetMapping("hi")
    public String hi() {
        return "hi";
    }

    @GetMapping("/suggestion")
    public List<String> suggestion(@RequestParam("key") String prefix) {

        log.info("[自动补全]prefix: {}", prefix);
        return searchService.ListSuggestion(prefix);
    }

    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody RequestParams params) {
        return searchService.filters(params);
    }

    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody RequestParams params) {
        return searchService.search(params);
    }
}
